var widget = {};
widget = {
    _UIDEFAULFS: {},
    _rebuildUiDefaults: function (options) {
        widget._UIDEFAULFS = Iptools.Tool._extend(widget._UIDEFAULFS, options);
    },
    _addEventListener: function (options) {
        $(options.container).on(options.type, options.target, options.event);
    },
    _bindingDomEvent: function () {
    },
    _bindingEventAfterLoad: function () {
    },
    _init: function () {
        widget._setAnalysisReport();
    },
    _setAnalysisReport: function () {
        $(".block-panel .block-num").loading();
        $('#analysis_report').loading();
        Iptools.GetJson({
            url: "system/getAnalysis",
            data: {
                token: Iptools.DEFAULTS.token
            }
        }).done(function (r) {
            if (r && r.data) {
                $("#totalCount").html(r.data.total);
                $("#todayCount").html(r.data.today);
                $("#feeCount").html(r.data.fee);
                //report
                var series = [];
                series.push({
                    type: 'spline',
                    name: '增长趋势',
                    data: r.report.lineData,
                    marker: {
                        lineWidth: 2,
                        lineColor: Highcharts.getOptions().colors[3],
                        fillColor: 'white'
                    }
                });
                for (var i = 0; i < r.report.pieData.length; i++) {
                    r.report.pieData[i].color = Highcharts.getOptions().colors[i + 1];
                }
                series.push({
                    type: 'pie',
                    name: '租户数量',
                    data: r.report.pieData,
                    center: [100, 80],
                    size: 100,
                    showInLegend: false,
                    dataLabels: {
                        enabled: false
                    },
                    tooltip: {
                        headerFormat: '{series.name}<br>',
                        pointFormat: '{point.name}: <b>{point.y}({point.percentage:.1f}%)</b>'
                    }
                });
                for (var i = 0; i < r.report.columnData.length; i++) {
                    r.report.columnData[i].type = "column";
                    series.push(r.report.columnData[i]);
                }
                $('#analysis_report').highcharts({
                    title: {
                        text: '平台租户进驻趋势'
                    },
                    xAxis: {
                        categories: r.report.categories
                    },
                    plotOptions: {
                        series: {
                            stacking: 'normal'
                        }
                    },
                    yAxis: {
                        title: {
                            text: "数量"
                        }
                    },
                    labels: {
                        items: [{
                            html: '渠道占比',
                            style: {
                                left: '100px',
                                top: '18px',
                                color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
                            }
                        }]
                    },
                    series: series
                });
            }
            if (r && r.table && r.table.length) {
                for (var i = 0; i < r.table.length; i++) {
                    var dt = r.table[i];
                    $("#a_table_body").append("<tr>" +
                        "<td>" + dt.phone + "</td>" +
                        "<td>" + dt.company_name + "</td>" +
                        "<td>" + dt.register_time + "</td>" +
                        "<td>" + dt.status + "</td>" +
                        "<td>" + dt.template + "</td>" +
                        "<td>" + dt.tenant_id + "</td>" +
                        "<td>" + dt.domain + "</td>" +
                        "<td>" + dt.employee_name + "</td>" +
                        "<td>" + dt.tenant_type + "</td>" +
                        "<td>" + dt.channel + "</td>" +
                        "</tr>");
                }
                $("#analysis_table_container").show();
            }
        }).fail(function () {
            $(".block-panel .block-num").html(0);
            $('#analysis_report').empty();
        });
    }
};